﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GongSiXX.aspx.cs" Inherits="Web.Pages.YongShui.JiChuXX.GongSiXX" Theme="Default" ValidateRequest="false" %>

<%@ Register Assembly="DevExpress.Web.v15.2, Version=15.2.9.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dx" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="../../../JS/AddEditCancel.js"></script>
    <script src="../../../JS/jquery.js"></script>
    <script type="text/javascript">
        function keyEnter(index) {
            var controls = new Array();
            controls[0] = document.getElementById("txtBianHao_I");
            controls[1] = document.getElementById("txtMingCheng_I");
            controls[2] = document.getElementById("txtDiZ_I");
            controls[3] = document.getElementById("ddlJuBH_I");
            controls[4] = document.getElementById("txtYouBian_I");
            controls[5] = document.getElementById("txtLianXiDH_I");
            controls[6] = document.getElementById("txtLianXiBM_I");
            controls[7] = document.getElementById("txtLianXiR_I");
            controls[8] = document.getElementById("txtBeiZhu_I");
            var key = event.keyCode;
            if (key == 13) {
                index = index + 1;
                if (index == controls.length) {
                    index = 0;
                }
                controls[index].focus();
            }
        }
    </script>
    <script type="text/javascript">
        function ClearInfo() {
            hdCollection.Set("ID", -1);
            txtBianHao.SetText("");
            txtMingCheng.SetText("");
            txtDiZ.SetText("");
            txtJuBH.SetText("");
            ddlJuBH.SetText("");
            txtYouBian.SetText("");
            txtLianXiDH.SetText("");
            txtLianXiBM.SetText("");
            txtLianXiR.SetText("");
            txtBeiZhu.SetText("");
        }

        function SetEnabled(enabled) {
            txtBianHao.SetEnabled(enabled);
            txtMingCheng.SetEnabled(enabled);
            txtDiZ.SetEnabled(enabled);
            txtJuBH.SetEnabled(enabled);
            ddlJuBH.SetEnabled(enabled);
            txtYouBian.SetEnabled(enabled);
            txtLianXiDH.SetEnabled(enabled);
            txtLianXiBM.SetEnabled(enabled);
            txtLianXiR.SetEnabled(enabled);
            txtBeiZhu.SetEnabled(enabled);
        }

        function display(op) {
            if (gvList.GetFocusedRowIndex() == -1) {
                return;
            }
            hdCollection.Set("op", op);
            if (hdCollection.Get("op") == "add" || hdCollection.Get("op") == "edit") {
                btnAdd.SetVisible(false);
                btnEdit.SetVisible(false);
                btnDel.SetVisible(false);
                btnSave.SetVisible(true);
                btnCancel.SetVisible(true);
                SetEnabled(true);
                listCover(true, "divList");
            }
            else if (hdCollection.Get("op") == "init") {
                btnAdd.SetVisible(true);
                btnEdit.SetVisible(true);
                btnDel.SetVisible(true);
                btnSave.SetVisible(false);
                btnCancel.SetVisible(false);
                SetEnabled(false);
                listCover(false, "divList");
            }
            else if (hdCollection.Get("op") == "ym") {
                if (conNianYu.GetText() == "历史年月") {
                    conLiShiNY.SetVisible(true);
                    btnAdd.SetVisible(false);
                    btnEdit.SetVisible(false);
                    btnDel.SetVisible(false);
                    ClearInfo();
                }
                else {
                    conLiShiNY.SetVisible(false);
                    btnAdd.SetVisible(true);
                    btnEdit.SetVisible(true);
                    btnDel.SetVisible(true)
                }
            }
            if (op == "add") {
                ClearInfo();
                txtBianHao.Focus();
            }
            else if (op == "edit") {
                txtBianHao.SetEnabled(false);
                txtMingCheng.Focus();
            }
            else if (op == "init") {               
                txtBianHao.SetEnabled(false);
                hdCollection.Set("ID", gvList.GetRowKey(gvList.GetFocusedRowIndex()));
                ASPxCallback1.PerformCallback("setinfo");
            }
        }

        function YMSelecedChange() {
            display("ym");
            bind();
        }

        function lishiny() {
            if (conLiShiNY.GetText().length!=6) {
                alert("请输入正确的历史年月。");
                return;
            }
            if (conLiShiNY.GetText() >= hdCollection.Get("YM"))
            {
                alert("历史年月应小于当前水量年月。");
                return;
            }
            bind();
        }
        
        function search() {
            if (conBH.GetText() == "") {
                return;
            }
            ASPxCallback1.PerformCallback("search");
        }

        function rowClick() {
            var id = -1;
            if (gvList.GetFocusedRowIndex() != -1) {
                id = gvList.GetRowKey(gvList.GetFocusedRowIndex());
                hdCollection.Set("ID", id);
                loadpanel1.Show();
                ASPxCallback1.PerformCallback("setinfo");

            }
            else {
                ClearInfo();
                hdCollection.Set("ID", id);
            }
        }
               
        function bind() {
            gvList.PerformCallback();
        }

        function save() {
            if (txtBianHao.GetText() == "") {
                alert("你没有输入公司的编号，请修改。");
                return;
            }
            if (txtMingCheng.GetText() == "") {
                alert("你没有输入公司的名称，请修改。");
                return;
            }
            ASPxCallback1.PerformCallback("save");
        }

        function del() {
            if (gvList.GetFocusedRowIndex() == -1) {
                alert("未选择公司。");
                return;
            }
            ASPxCallback1.PerformCallback("deleteValidate");
        }

        function ASPxCallback1Complete(rs) {
            var arr = rs.split('|');
            var type = arr[0];
            var state = arr[1];
            loadpanel1.Hide();
            if (state != "0") {
                alert(arr[2]);
            }
            else {
                if (type == "save") {
                    alert(arr[2]);
                    display("init");
                    if (conNianYu.GetText() == "下一月" || conNianYu.GetText() == "当前月") {
                        bind();
                    }
                }
                else if (type == "deleteValidate") {
                    if (confirm("当前公司没有用户使用,你确定要删除吗？")) {
                        ASPxCallback1.PerformCallback("delete");
                    }
                }
                else if (type == "delete") {
                    alert(arr[2]);
                    ClearInfo();
                    gvList.PerformCallback();
                }
                else if (type == "search") {
                    gvList.SetFocusedRowIndex(arr[2]);
                    gvList.MakeRowVisible(arr[2]);
                }
                else if (type == "setinfo") {
                    txtBianHao.SetText(arr[2]);
                    txtMingCheng.SetText(arr[3]);
                    txtDiZ.SetText(arr[4]);
                    txtJuBH.SetText(arr[5]);
                    ddlJuBH.SetValue(arr[5]);
                    txtYouBian.SetText(arr[6]);
                    txtLianXiDH.SetText(arr[7]);
                    txtLianXiBM.SetText(arr[8]);
                    txtLianXiR.SetText(arr[9]);
                    txtBeiZhu.SetText(arr[10]);
                }
            }
        }
</script>
</head>
<body style="overflow:hidden">
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <div class="tabletitle1" align="center">
            公司信息
        </div>       
                <div style="display: none;">
                    <dx:ASPxHiddenField ID="hdCollection" ClientInstanceName="hdCollection" runat="server"></dx:ASPxHiddenField>
                    <dx:ASPxButton ID="btnActPerform" ClientInstanceName="btnActPerform" runat="server" Text="ASPxButton"></dx:ASPxButton>
                    <dx:ASPxCallback ID="ASPxCallback1" ClientInstanceName="ASPxCallback1" runat="server" OnCallback="ASPxCallback1_Callback" ClientSideEvents-CallbackComplete="function(s,e){ASPxCallback1Complete(e.result);}"></dx:ASPxCallback>
                </div>
                <div style="width: 100%">
                    <div style="float: left; width: 45%;" id="divList">
                        <table width="100%" border="0">
                            <tr>
                                <td colspan="3">
                                    <table style="width: 100%">
                                        <tr>
                                            <td style="white-space: nowrap; width: 1%">站点：</td>
                                            <td style="width: 30%">
                                                <dx:ASPxComboBox runat="server" ID="conZhanDian" ClientInstanceName="conZhanDian" Width="100%" ClientSideEvents-SelectedIndexChanged="function(s,e){bind();}">
                                                </dx:ASPxComboBox>
                                            </td>
                                            <td style="width: 30%">
                                                <asp:Panel runat="server" ID="panNianYue">
                                                    <dx:ASPxComboBox runat="server" ID="conNianYu" ClientInstanceName="conNianYu" Width="100%" AutoPostBack="false" ClientSideEvents-SelectedIndexChanged="function(s,e){YMSelecedChange();}">
                                                        <Items>
                                                            <dx:ListEditItem Text="当前月" Value="0" Selected="true" />
                                                            <dx:ListEditItem Text="下一月" Value="1" />
                                                            <dx:ListEditItem Text="历史年月" Value="3" />
                                                        </Items>
                                                    </dx:ASPxComboBox>
                                                </asp:Panel>
                                            </td>
                                            <td style="width: 30%">
                                                <dx:ASPxTextBox ID="conLiShiNY" ClientInstanceName="conLiShiNY" runat="server" Width="100%" ClientVisible="false">
                                                    <ClientSideEvents KeyUp="function(s,e){inputNum(s);var key = event.keyCode;
                                                    if( key==13){lishiny();}}" />
                                                </dx:ASPxTextBox>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr>
                                <td style="white-space: nowrap; width: 1%;">公司编号/公司名称：</td>
                                <td style="width: 40%">
                                    <dx:ASPxTextBox ID="conBH" ClientInstanceName="conBH" runat="server" Width="100%">
                                        <ClientSideEvents KeyPress="function(s,e){var key = event.keyCode;
                                        if( key==13){search();}}" />
                                    </dx:ASPxTextBox>
                                </td>
                                <td>
                                    <dx:ASPxButton ID="btnSearch" ClientInstanceName="btnSearch" runat="server" Text="查询" UseSubmitBehavior="false" AutoPostBack="false" ClientSideEvents-Click="function(s,e){search();}">
                                    </dx:ASPxButton>
                                </td>
                            </tr>
                        </table>
                         <asp:UpdatePanel runat="server" ID="UpdatePanel1">
            <ContentTemplate>
                        <dx:ASPxGridView ID="gvList" ClientInstanceName="gvList" runat="server" AutoGenerateColumns="False" KeyFieldName="ID" Theme="Aqua1"
                            Width="100%" OnCustomCallback="gvList_CustomCallback" EnableCallBacks="true">
                            <Columns>
                                <dx:GridViewDataTextColumn FieldName="S_JUBIANH" Caption="局编号" Width="15%">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn FieldName="S_BIANHAO" Caption="公司编号" Width="15%">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn FieldName="S_MINGCHENG" Caption="公司名称" Width="70%">
                                </dx:GridViewDataTextColumn>
                            </Columns>
                            <SettingsBehavior AllowFocusedRow="True" ColumnResizeMode="Control"  ProcessFocusedRowChangedOnServer="false" />
                            <Settings VerticalScrollableHeight="440" VerticalScrollBarMode="Auto" />
                             <ClientSideEvents FocusedRowChanged="function(s,e){rowClick();}" EndCallback="function(s,e){rowClick();}"  Init="function(s,e){AdjustSize(100,gvList);}"/>
                        </dx:ASPxGridView>                
            </ContentTemplate>
        </asp:UpdatePanel>
                         <dx:ASPxLoadingPanel ID="ASPxLoadingPanel1" ClientInstanceName="loadpanel1" runat="server" ContainerElementID="gvList" Modal="true" Theme="Metropolis" Text=""></dx:ASPxLoadingPanel>
                        <dx:ASPxLoadingPanel ID="ASPxLoadingPanel2" ClientInstanceName="loadpanel2" runat="server"  Text="加载中..."></dx:ASPxLoadingPanel>
                    </div>
                    <div style="float: left; width: 1%;">&nbsp;</div>
                    <div style="float: left; width: 53%; overflow: auto;">
                        <table style="width: 100%" id="GridViewContentTable" runat="server">
                            <tr>
                                <td align="right" style="width: 20%; white-space: nowrap;">公司编号：
                                </td>
                                <td style="width: 30%">
                                    <dx:ASPxTextBox ID="txtBianHao" ClientInstanceName="txtBianHao" ClientEnabled="false" runat="server" Width="100%" MaxLength="5">
                                        <ClientSideEvents  KeyUp="function(s,e){inputNum(s);keyEnter(0);}" />
                                    </dx:ASPxTextBox>
                                </td>
                                <td style="width: 20%"></td>
                                <td style="width: 30%"></td>
                            </tr>
                            <tr>
                                <td align="right">公司名称：
                                </td>
                                <td colspan="3">
                                    <dx:ASPxTextBox ID="txtMingCheng" ClientInstanceName="txtMingCheng" ClientEnabled="false" runat="server" Text="" Width="100%" MaxLength="50">

                                        <ClientSideEvents KeyPress="function(s,e){keyEnter(1);}" />
                                    </dx:ASPxTextBox>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">公司地址：
                                </td>
                                <td colspan="3">
                                    <dx:ASPxTextBox ID="txtDiZ" ClientInstanceName="txtDiZ" ClientEnabled="false" runat="server" Width="100%" MaxLength="100">
                                        <ClientSideEvents KeyPress="function(s,e){keyEnter(2);}" />
                                    </dx:ASPxTextBox>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">局编号：
                                </td>
                                <td>
                                    <dx:ASPxTextBox ID="txtJuBH" ClientInstanceName="txtJuBH" ClientEnabled="false" runat="server" Width="100%" MaxLength="5">
                                    </dx:ASPxTextBox>
                                </td>
                                <td colspan="2">
                                    <dx:ASPxComboBox runat="server" ID="ddlJuBH" ClientInstanceName="ddlJuBH" ClientEnabled="false" Width="100%" DropDownStyle="DropDownList">
                                        <ClientSideEvents KeyPress="function(s,e){keyEnter(3);}" />
                                    </dx:ASPxComboBox>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">邮编：
                                </td>
                                <td>
                                    <dx:ASPxTextBox ID="txtYouBian" ClientInstanceName="txtYouBian" ClientEnabled="false" runat="server" Width="100%" MaxLength="15">
                                        <ClientSideEvents KeyPress="function(s,e){keyEnter(4);}" />
                                    </dx:ASPxTextBox>
                                </td>
                                <td align="right" style="white-space: nowrap;">联系电话：
                                </td>
                                <td>
                                    <dx:ASPxTextBox ID="txtLianXiDH" ClientInstanceName="txtLianXiDH" ClientEnabled="false" runat="server" Width="100%" MaxLength="50">
                                        <ClientSideEvents KeyPress="function(s,e){keyEnter(5);}" />
                                    </dx:ASPxTextBox>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">联系部门：
                                </td>
                                <td>
                                    <dx:ASPxTextBox ID="txtLianXiBM" ClientInstanceName="txtLianXiBM" ClientEnabled="false" runat="server" Width="100%" MaxLength="30">
                                        <ClientSideEvents KeyPress="function(s,e){keyEnter(6);}" />
                                    </dx:ASPxTextBox>
                                </td>
                                <td align="right">联系人：
                                </td>
                                <td>
                                    <dx:ASPxTextBox ID="txtLianXiR" ClientInstanceName="txtLianXiR" ClientEnabled="false" runat="server" Width="100%" MaxLength="30">
                                        <ClientSideEvents KeyPress="function(s,e){keyEnter(7);}" />
                                    </dx:ASPxTextBox>
                                </td>
                            </tr>
                            <tr>
                                <td align="right" valign="top">备注：
                                </td>
                                <td colspan="3">
                                    <dx:ASPxMemo ID="txtBeiZhu" ClientInstanceName="txtBeiZhu" ClientEnabled="false" runat="server" Width="100%" MaxLength="133">
                                        <ClientSideEvents KeyPress="function(s,e){OnKeyNext(btnSave);}" />
                                    </dx:ASPxMemo>
                                </td>
                            </tr>
                        </table>
                        <div align="right">
                            <hr />
                            <dx:ASPxButton ID="btnAdd" ClientInstanceName="btnAdd" runat="server" Text="添加" AutoPostBack="false" UseSubmitBehavior="false" ClientSideEvents-Click="function(s,e){display('add');}">
                                        </dx:ASPxButton>
                                        <dx:ASPxButton ID="btnEdit" ClientInstanceName="btnEdit" runat="server" Text="修改" AutoPostBack="false" UseSubmitBehavior="false" ClientSideEvents-Click="function(s,e){display('edit');}">
                                        </dx:ASPxButton>
                                        <dx:ASPxButton ID="btnDel" ClientInstanceName="btnDel" runat="server" Text="删除" AutoPostBack="false" UseSubmitBehavior="false" ClientSideEvents-Click="function(s,e){del();}">
                                        </dx:ASPxButton>
                                        <dx:ASPxButton ID="btnSave" ClientInstanceName="btnSave" runat="server" Text="保存" ClientVisible="false" AutoPostBack="false" UseSubmitBehavior="false">
                                            <ClientSideEvents Click="function(s, e){save();}" />
                                        </dx:ASPxButton>
                                        <dx:ASPxButton ID="btnCancel" ClientInstanceName="btnCancel" runat="server" Text="放弃" ClientVisible="false" AutoPostBack="false" UseSubmitBehavior="false" ClientSideEvents-Click="function(s,e){display('init');}">
                                        </dx:ASPxButton>
                        </div>
                    </div>
                </div>
    </form>
</body>
</html>


